package cmd

import (
	global2 "longmen/server/config/global"
	esports2 "longmen/server/internal/services/nami/api/v5/esports"
	"longmen/server/internal/services/nami/api/v5/esports/csgo"
	"longmen/server/internal/services/nami/api/v5/esports/dota2"
	"longmen/server/internal/services/nami/api/v5/esports/lol"
	"longmen/server/internal/services/nami/config"
	"sync"

	"github.com/spf13/cobra"
	esModel "longmen/server/pkg/db/mysql/models/models_esports"
)

var testEsport = &cobra.Command{
	Use:   "esport",
	Short: "测试抓取电竞数据",
	Long:  "测试抓取电竞数据",
	Run: func(cmd *cobra.Command, args []string) {
		esports2.SyncLiveUrl()

		global2.Sport().AutoMigrate(
			esModel.CsgoTournament{},
			esModel.CsgoTeam{},
			esModel.LolTournament{},
			esModel.LolTeam{},
			esModel.Dota2Tournament{},
			esModel.Dota2Team{},
		)
		var syncInterFace = []esports2.ESportSyncInterface{
			lol.LOL{},
			csgo.Csgo{},
			dota2.Dota2{},
		}
		for _, face := range syncInterFace {
			face.SyncInitTeam()
			face.SyncInitTournament()
		}

		wg := sync.WaitGroup{}
		for _, item := range syncInterFace {
			wg.Add(1)
			go func(face esports2.ESportSyncInterface) {
				defer wg.Done()
				face.SyncTournament()
				face.SyncTeam()
				face.SyncMatch()
				face.SyncDelete()
			}(item)
		}
		wg.Wait()
	},
	PreRun: func(cmd *cobra.Command, args []string) {
		global2.Initialize(configFile)
		config.InitConfig()
	},
	PostRun: func(cmd *cobra.Command, args []string) {

	},
}
